package com.qpx.springbootdemo1.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.qpx.springbootdemo1.SpringbootDemo1Application;
import com.qpx.springbootdemo1.entity.Test;
import com.qpx.springbootdemo1.service.TestService;
import com.qpx.springbootdemo1.vo.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TestController {

    Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    TestService testService;

    @RequestMapping("/insertBatch")
    public ResultEntity insertBatch(){

        List<Test> list = new ArrayList<>();
        for (int i = 0;i<10000;i++){
            Test test = new Test();
            test.setName("zhangsan"+i);
            list.add(test);
        }
        long beginTime = System.currentTimeMillis();
        testService.insertBatchTest(list);
        long endTime = System.currentTimeMillis();
        logger.info("查询时间为:{}毫秒",endTime-beginTime);
        return ResultEntity.ok();
    }

    @RequestMapping("/get")
    public ResultEntity get(){
        Wrapper wrapper = new EntityWrapper();
        long beginTime = System.currentTimeMillis();
        List list = testService.selectList(wrapper);
        long endTime = System.currentTimeMillis();
        logger.info("查询时间为:{}毫秒",endTime-beginTime);
        return ResultEntity.ok();
    }

}
